from models import PageView
from simplestats.registration import registrar

class RegexLoggingMiddleware(object):
    def process_request(self, request):
        path = request.get_full_path()
        if not path:
            path = request.path
        if registrar.should_log(path):
            pv = PageView(
                path = path,
                method = request.method,
                remote_addr = request.META.get('REMOTE_ADDR', ''),
                http_referrer = request.META.get('HTTP_REFERER', '')
            )
            pv.save()

class AllLoggingMiddleware(object):
    def process_request(self, request):
        path = request.get_full_path()
        if not path:
            path = request.path
        pv = PageView(
            path = path,
            method = request.method,
            remote_addr = request.META.get('REMOTE_ADDR', ''),
            http_referrer = request.META.get('HTTP_REFERER', '')
        )
        pv.save()